using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Keep.Const;
using Keep.Model;
using Keep.Service;
using Microsoft.AspNetCore.Mvc;
using Serilog;

namespace Keep.Controllers;

[ApiController]
[Route("api/[controller]/[action]")]
public class MusicListController : ControllerBase
{
    private readonly IMusicListService musicListService;

    public MusicListController(IMusicListService musicListService)
    {
        this.musicListService = musicListService;
    }
    //大概率废弃
    [HttpPost(Name = "SelMusicList")]
    public async Task<ActionResult<ResultData>> SelMusicList(MusicList musicList)
    {
        Log.Warning("IN");
        List<MusicList> sys = await Task.Run(() => musicListService.SelMusicList(musicList));
        Log.Warning("OUT => " + sys.ToString() + "  数量:" + sys.Count);
        return Ok(new ResultData(Static.Enable, sys));
    }

    [HttpPost(Name = "AddMusicList")]
    public async Task<ActionResult<ResultData>> AddMusicList(MusicList musicList)
    {
        Log.Warning("IN");
        bool sys = await Task.Run(() => musicListService.AddMusicList(musicList));
        Log.Warning("OUT => " + sys);
        return Ok(new ResultData(Static.Enable, sys));
    }

    [HttpPost(Name = "EditMusicList")]
    public async Task<ActionResult<ResultData>> EditMusicList(MusicList musicList)
    {
        Log.Warning("IN");
        bool sys = await Task.Run(() => musicListService.EditMusicList(musicList));
        Log.Warning("OUT => " + sys);
        return Ok(new ResultData(Static.Enable, sys));
    }

    [HttpPost(Name = "DelMusicList")]
    public async Task<ActionResult<ResultData>> DelMusicList(MusicList musicList)
    {
        Log.Warning("IN");
        bool sys = await Task.Run(() => musicListService.DelMusicList((int)musicList.id));
        Log.Warning("OUT => " + sys);
        return Ok(new ResultData(Static.Enable, sys));
    }

}
